package com.texplose.controller;

import com.texplose.entity.User;
import com.texplose.entity.vo.ResponseResult;
import com.texplose.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author : cyj
 * @Timer : 2022/5/17
 * @Description :
 */
@RestController
@RequestMapping(("/admin/user"))
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/login")
    public ResponseResult adminLogin(@RequestBody User user) {
        return userService.adminLogin(user);
    }

    @GetMapping("/getUserById/{id}")
    public ResponseResult getUserById(@PathVariable("id") Integer id) {
        return userService.getUserById(id);
    }

    @GetMapping("/selectAllUser")
    public ResponseResult selectAllUser() {
        return userService.selectAllUser();
    }

    /**
     * 分页查询
     * @param pageNum 第几页
     * @param pageSize 每页几条数据
     * @return
     */
    @GetMapping("/findAllByPage")
    public ResponseResult findAllByPage(int pageNum,int pageSize) {
        return userService.findAll(pageNum, pageSize);
    }

    @DeleteMapping("/delete")
    public ResponseResult deleteUser(@RequestBody User user) {
        return userService.deleteUser(user.getUserId());
    }
}
